/**
 * This program is free software but WITHOUT ANY WARRANTY OR CONDITIONS OF ANY KIND.
 *
 * Copyright (C) 2008-2013 www.pretty-tools.com
 */

var WEBSLIDESHOW_UPDATE_CONFIGURATION_EVENT = "webslideshow-update-configuration";

/**
 * Configuration
 */
function wsshConfiguration()
{
    this.logger = yrprxFactory.createLogger("wsshConfiguration");

    var cfg = this;

    this.logger.debug("loading configuration");
    chrome.runtime.sendMessage({clone: "wsshConfig"}, function(response) {

        cfg.copyFrom(response.value);

        cfg.logger.debug("configuration loaded");

        if (window["onConfiguration"])
            onConfiguration();
    });

    this.configObserver = {
        observe: function(subject, topic, data) {

            cfg.copyFrom(data);

            cfg.logger.debug("configuration updated");

            if (window["onConfigurationUpdated"])
                onConfigurationUpdated();
        }
    };

    // subscribe
    yrprxObserverServiceHelper.addObserver(this.configObserver, WEBSLIDESHOW_UPDATE_CONFIGURATION_EVENT);
}

wsshConfiguration.prototype.copyFrom = function(cfg)
{
    for (var i in cfg)
        this[i] = cfg[i];
}

var wsshConfig = new wsshConfiguration();
